#include "board.h"
#include "rtthread.h"

static void receive_thread_entry(void* parameter);
static void send_thread_entry(void* parameter);

static rt_thread_t receive_thread = RT_NULL;
static rt_thread_t send_thread = RT_NULL;

static rt_mq_t test_mq = RT_NULL;
int main(void)
{	
		ILI9341_GramScan ( 6 );//设置显示模式
		LED_Color(LED_OFF);
		test_mq = rt_mq_create("test",40,20,RT_IPC_FLAG_FIFO);
	
    receive_thread = 
			rt_thread_create("receive_thread",receive_thread_entry,RT_NULL,512,3,20);
	  rt_thread_startup(receive_thread);
	
		send_thread = 
				rt_thread_create("send_thread",send_thread_entry,RT_NULL,512,3,20);
		rt_thread_startup(send_thread);	
}

static void receive_thread_entry(void* parameter)
{
	rt_err_t uwRet = RT_EOK;
	uint32_t r_queue;
	while(1)
	{
		uwRet = rt_mq_recv(test_mq,&r_queue,sizeof(r_queue),RT_WAITING_FOREVER);
		if(uwRet == RT_EOK)
		{
			rt_kprintf("Data:%d\n",r_queue);
		}
		rt_thread_delay(200);
	}
}

static void send_thread_entry(void* parameter)
{
	rt_err_t uwRet = RT_EOK;
	uint32_t send_data1 = 1;
	uint32_t send_data2 = 222;
	while(1)
	{
		if(GET_KEY1)
		{
				uwRet = rt_mq_send(test_mq,/* 写入（发送）队列的 ID(句柄) */
													&send_data1,/* 写入（发送）的数据 */
													sizeof(send_data1)); /* 数据的长度 */
		}
		if(GET_KEY2)
		{
				uwRet = rt_mq_send(test_mq,/* 写入（发送）队列的 ID(句柄) */
													&send_data2,/* 写入（发送）的数据 */
													sizeof(send_data2)); /* 数据的长度 */
		}
		rt_thread_delay(20);
	}
}
